using Dapr.AppCallback.Autogen.Grpc.v1;
using Dapr.Client;
using Dapr.Client.Autogen.Grpc.v1;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;

namespace Kevin.Dapr.UserService.Services
{
    public partial class DaprGrpcService : AppCallback.AppCallbackBase
    {
        public override async Task<InvokeResponse> OnInvoke(InvokeRequest request, ServerCallContext context)
        {
            var response = new InvokeResponse();            
            switch (request.Method)
            {
                case "login":
                    var input = request.Data.Unpack<LoginInput>();
                    var data = new LoginOutput
                    {
                        Id = 1000,
                        Name = "超级管理员",
                        UserName = input.UserName + input.Password,
                        Age = 22,
                        Address = "天府五街"
                    };
                    response.Data = Any.Pack(data);
                    break;
                    //case "savestorage":
                    //    await _daprClient.SaveStateAsync("statestore", "login:admin:1000", new LoginOutput
                    //    {
                    //        Id = 1000,
                    //        Name = "超级管理员",
                    //        Age = 18,
                    //        UserName = "admin",
                    //        Address = "天府五街"
                    //    });
                    //    break;
                    //case "getstorage":
                    //    var data = await _daprClient.GetStateAsync<LoginOutput>("statestore", "login:admin:1000");
                    //    //IList<ListUserOutput> results = new List<ListUserOutput> {
                    //    //    new ListUserOutput { Id = 99,  Age = 33, UserName ="王七", Address ="成都" } ,
                    //    //    new ListUserOutput { Id = 98,  Age = 54, UserName ="李无", Address ="北京" } ,
                    //    //    new ListUserOutput { Id = 97,  Age = 28, UserName ="订单", Address ="上海" } ,
                    //    //};
                    //    //var data = new ListOutput { new RepeatedField<string> { "sadfasdf", "sdfasdfad" } };
                    //    response.Data = Any.Pack(data);
                    //    break;
            }
            return response;
        }
    }

    //public partial class UserService
    //{
    //    private readonly DaprClient _daprClient;

    //    public UserService(DaprClient daprClient)
    //    {
    //        _daprClient = daprClient;
    //    }
    //}
}
